package com.itheima.mymap;

import java.util.*;

public class Demo2 {
    public static void main(String[] args) {
        HashMap<String,ArrayList<String>> hashMap = new HashMap<>();
        ArrayList<String> sgyy = new ArrayList<>();
        Collections.addAll(sgyy,"诸葛亮","赵云");
        hashMap.put("三国演义",sgyy);
        ArrayList<String> xyj = new ArrayList<>();
        Collections.addAll(xyj,"唐僧","孙悟空");
        hashMap.put("西游记",xyj);
        ArrayList<String> shz = new ArrayList<>();
        Collections.addAll(shz,"武松","鲁智深");
        hashMap.put("水浒传",shz);
        //遍历集合
        Set<String> keys = hashMap.keySet();
        for (String key : keys) {
            ArrayList<String> list = hashMap.get(key);
            System.out.println(key+": ");
            System.out.print("\t");
            for (int i = 0; i < list.size(); i++) {
                String s = list.get(i);
                if( i % 2 == 1 ||i == list.size()-1){
                    if (i==3) {
                        System.out.println(s);
                    }else {
                    System.out.println(s);
                    System.out.print("\t");
                    }
                }else {
                    System.out.print(s+",");
                }
            }
        }
    }
}
